<template>
  <div style="height:100%;">
    <van-nav-bar title="登陆" left-text="返回" @click-left="onClickLeft" left-arrow />
    <lazy-component>
    <div class="backlogin">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="username"
          label="账号  :"
          placeholder="请输入账号"
          :rules="[{ required: true, message: '请填写账号' }]"
          style="margin-top:0;"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码  :"
          placeholder="请输入密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
      </van-form>
    </div>
    </lazy-component>
  </div>
</template>

<script>
//登陆页
import Vue from 'vue';
import { Lazyload } from 'vant';

Vue.use(Lazyload, {
  lazyComponent: true,
});
import { postuser } from "@/request/API/subject.js";
export default {
  name: "login",
  data() {
    return {
      username: "",
      password: ""
    };
  },
  methods: {
    async onSubmit(data) {
      let res = await postuser(data,{
        headers: { "Content-Type": "application/json" },
      });
      let userData = res.data
      let token = userData.token
      this.$router.push({path:"/"})
      this.$store.commit("apiDataModules/POSTTOKEN",token)
    },
    onClickLeft() {
      this.$router.push({path:"/"});
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/style/login/login.scss";
</style>